//
//  HearLoginRootView.m
//  Hear
//
//  Created by mac on 2017/3/22.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HearLoginRootView.h"
#import <UMSocialCore/UMSocialCore.h>
@interface HearLoginRootView ()
@property (nonatomic, strong)UIButton *phoneEnterButton;

@end
@implementation HearLoginRootView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        
        
        UIImageView *backImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"提示耳机图案"]];
        backImageView.contentMode = UIViewContentModeScaleAspectFill;
        backImageView.clipsToBounds = YES;
        [self addSubview:backImageView];
        backImageView.userInteractionEnabled = YES;
        
        
        self.phoneEnterButton = [UIButton buttonWithType:1];
        [self.phoneEnterButton setTitle:@"手机号登录" forState:UIControlStateNormal];
        [self.phoneEnterButton setTitleColor:[TEXTCOLOR colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        self.phoneEnterButton.titleLabel.font = CustomUIFont(17);
        [self.phoneEnterButton addTarget:self action:@selector(phoneEnterButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.phoneEnterButton];
        self.phoneEnterButton.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
        self.phoneEnterButton.layer.cornerRadius = 8;
        self.phoneEnterButton.clipsToBounds = YES;
        
        
        UILabel *otherLoginLabel = [UILabel new];
        otherLoginLabel.text = @"第三方账号登录";
        otherLoginLabel.textAlignment = 1;
        otherLoginLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
        otherLoginLabel.font = CustomUIFont(13);
        [self addSubview:otherLoginLabel];
        
        UILabel *leftLineLabel = [UILabel new];
        leftLineLabel.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
        [self addSubview:leftLineLabel];
        
        UILabel *rightLineLabel = [UILabel new];
        rightLineLabel.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7];
        [self addSubview:rightLineLabel];

        
        UIButton *wxButton = [UIButton buttonWithType:0];
        [wxButton setImage:[UIImage imageNamed:@"微信"] forState:UIControlStateNormal];
        [wxButton addTarget:self action:@selector(otherLoginClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:wxButton];
        wxButton.tag = 0;
        wxButton.hidden = ![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_WechatSession];
        
        
        UIButton *wbButton = [UIButton buttonWithType:0];
        [wbButton setImage:[UIImage imageNamed:@"微博"] forState:UIControlStateNormal];
        [wbButton addTarget:self action:@selector(otherLoginClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:wbButton];
        wbButton.tag = 1;
        wbButton.hidden = ![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_Sina];
        wbButton.hidden = YES;
        
        UIButton *qqButton = [UIButton buttonWithType:0];
        [qqButton setImage:[UIImage imageNamed:@"QQ"] forState:UIControlStateNormal];
        [qqButton addTarget:self action:@selector(otherLoginClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:qqButton];
        qqButton.tag = 2;
        qqButton.hidden = ![[UMSocialManager defaultManager] isInstall:UMSocialPlatformType_QQ];

        
        UIButton *protocolButton = [UIButton buttonWithType:1];
        [protocolButton setTitle:@"登录即代表同意用户协议" forState:UIControlStateNormal];
        [protocolButton setTitleColor:[[UIColor whiteColor] colorWithAlphaComponent:0.7] forState:UIControlStateNormal];
        protocolButton.titleLabel.font = CustomUIFont(13);
        [protocolButton addTarget:self action:@selector(protocolButtonClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:protocolButton];
        
        WeakSelf
        [backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(weakSelf);
        }];
        
        [self.phoneEnterButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(30);
            make.right.mas_equalTo(-30);
            make.centerY.equalTo(weakSelf).offset(100);
            make.height.mas_equalTo(45);
        }];
        
        [otherLoginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.size.mas_equalTo(CGSizeMake(100, 20));
            make.bottom.equalTo(self.phoneEnterButton).offset(40);
        }];
        
        
        [leftLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf).offset(15);
            make.right.equalTo(otherLoginLabel.mas_left);
            make.top.equalTo(otherLoginLabel).offset(10);
            make.height.mas_equalTo(0.7);
        }];
        
        [rightLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(otherLoginLabel.mas_right);
            make.right.equalTo(self).offset(-15);
            make.top.equalTo(leftLineLabel);
            make.height.equalTo(leftLineLabel);
        }];
        
        
        [wxButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(40, 40));
            make.centerX.equalTo(weakSelf).offset(-30);
            make.top.equalTo(otherLoginLabel.mas_bottom).offset(20);
        }];
        
//        [wbButton mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.size.mas_equalTo(CGSizeMake(40, 40));
//            make.right.equalTo(wxButton.mas_left).offset(-20);
//            make.top.equalTo(wxButton.mas_top);
//        }];
        
        [qqButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(40, 40));
            make.centerX.equalTo(weakSelf).offset(30);
            make.top.equalTo(wxButton.mas_top);
        }];
        
        [protocolButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf);
            make.bottom.equalTo(weakSelf).offset(-30);
            make.size.mas_equalTo(CGSizeMake(160, 30));
            
        }];
        
        
    }
    return self;
}

#pragma -mark- 手机号登录
- (void)phoneEnterButtonClick
{
    if (self.phoneClickBlock)
    {
        self.phoneClickBlock();
    }
}

#pragma -mark- 第三方登录
- (void)otherLoginClick:(id)sender
{
    if (self.otherClickBlock)
    {
        self.otherClickBlock([(UIButton *)sender tag]);
    }
}
#pragma -mark- 用户协议
- (void)protocolButtonClick
{
    if (self.protocolClickBlock)
    {
        self.protocolClickBlock();
    }
}


@end
